package com.tsu.mall.admin.aspect;

import com.tsu.mall.admin.service.ILogService;
import com.tsu.mall.admin.util.RequestUtil;
import com.tsu.mall.common.VO.LayuiTableVO;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.annotation.AfterReturning;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before;
import org.aspectj.lang.annotation.Pointcut;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.text.SimpleDateFormat;
import java.util.Date;

//记录日志的切面
@Aspect    //切面对象
@Component //让Spring创建对象
public class LogAspect {
    @Autowired
    private ILogService iLogService;
    @AfterReturning(pointcut = "execution(* com.tsu.mall.admin.controller.LoginController.*(..))",returning = "result")
    public void log1(LayuiTableVO result){
        if (result.getCode() == 1){
            return;
        }
        //将登录日志记录
        iLogService.doAddLog(RequestUtil.getCurrent().getUsername()+"在"+new SimpleDateFormat("yyyy-MM-dd HH:mm:ss").format(new Date())+"成功登录");
    }
}
